#! /bin/sh
#
# susan       This shell script takes care of starting and stopping
#	       the susan daemons.
#
# description: Backup Archiving REcovery Open Sourced.
#
#
export SUSAN_CONFIG_DIR=${SUSAN_CONFIG_DIR:-@confdir@}
SUSAN_SCRIPTDIR=${SUSAN_SCRIPTDIR:-@scriptdir@}
#
# Disable Glibc malloc checks, it doesn't help and it keeps from getting
#   good dumps
MALLOC_CHECK_=0
export MALLOC_CHECK_

case "$1" in
   start)
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-sd ] && ${SUSAN_SCRIPTDIR}/susan-ctl-sd $1 $2
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-fd ] && ${SUSAN_SCRIPTDIR}/susan-ctl-fd $1 $2
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-dir ] && ${SUSAN_SCRIPTDIR}/susan-ctl-dir $1 $2
      ;;

   stop)
      # Stop the FD first so that SD will fail jobs and update catalog
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-fd ] && ${SUSAN_SCRIPTDIR}/susan-ctl-fd $1 $2
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-sd ] && ${SUSAN_SCRIPTDIR}/susan-ctl-sd $1 $2
      [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-dir ] && ${SUSAN_SCRIPTDIR}/susan-ctl-dir $1 $2
      ;;

   restart)
      $0 stop
      sleep 2
      $0 start
      ;;

   status)
      if [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-dir ]; then
         ${SUSAN_SCRIPTDIR}/susan-ctl-dir status
         status_dir=$?
      fi
      if [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-sd ]; then
         ${SUSAN_SCRIPTDIR}/susan-ctl-sd status
         status_sd=$?
      fi
      if [ -x ${SUSAN_SCRIPTDIR}/susan-ctl-fd ]; then
         ${SUSAN_SCRIPTDIR}/susan-ctl-fd status
         status_fd=$?
      fi
      status_all=`expr ${status_dir:-0} + ${status_sd:-0} + ${status_fd:-0}`
      exit ${status_all}
      ;;

   *)
      echo "Usage: $0 {start|stop|restart|status}"
      exit 1
      ;;
esac
exit 0
